package com.discovery.service.impl;

import com.discovery.common.ret.ServiceException;
import com.discovery.core.generalMap.AbstractMybatisMapperService;
import com.discovery.dao.UserInfoMapper;
import com.discovery.model.UserInfo;
import com.discovery.service.UserInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserInfoServiceImpl extends AbstractMybatisMapperService<UserInfo> implements UserInfoService {

    @Resource
    private UserInfoMapper userInfoDao;

    @Override
    public UserInfo selectById(Object id) {
        UserInfo userInfo = userInfoDao.selectByPrimaryKey(id);
        if(userInfo == null){
            throw new ServiceException("暂无该用户");
        }
        return userInfo;
    }

    public PageInfo<UserInfo> selectAll(Integer page, Integer size) {
            //开启分页查询，写在查询语句上方
            //只有紧跟在PageHelper.startPage方法后的第一个Mybatis的查询（Select）方法会被分页。
            PageHelper.startPage(page, size);
            List<UserInfo> userInfoList = userInfoDao.selectAll();
        return new PageInfo<>(userInfoList);
    }
}
